//
//  MineHeaderCell.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/1/27.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "MineHeaderCell.h"
#import <SDWebImage/UIButton+WebCache.h>
#import "CYLevel.h"
@implementation MineHeaderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.headerImage.size = CGSizeMake(45, 45);
    self.headerImage.layer.cornerRadius = 70/2;
    self.headerImage.layer.masksToBounds = YES;
    [self layoutIfNeeded];
    
    CALayer *layer = [CALayer layer];
    
    layer.frame = self.headerImage.bounds;
    layer.backgroundColor = KWhiteColor.CGColor;
    layer.shadowOffset = CGSizeMake(0, 5);
    layer.shadowColor=[UIColor grayColor].CGColor;
    layer.cornerRadius = 70/2;
    layer.shadowOpacity = 0.7;
    layer.shadowColor = RGB(233, 233, 233).CGColor;
    //    layer.cornerRadius = 10;
    
    //这里self表示当前自定义的view
    
    [self.headerSupper.layer addSublayer:layer];
    
    
    //关注 粉丝 分成比例的颜色
    self.labAttr.textColor = CLightGray;
    self.labFans.textColor = CLightGray;
    self.labRate.textColor = CLightGray;
    
    
    self.userNickname = [[UILabel alloc] init];
    [self addSubview:self.userNickname];
    self.level = [[QMUIFillButton alloc] init];
    [self addSubview:self.level];
    
    self.LBids = [[UILabel alloc] init];
    self.LBids.text = NSStringFormat(@"ID:%@",curUser.id);
    self.LBids.font = DEFAULT_FONT(11);
    [self addSubview:self.LBids];
    
    self.userNickname.font = DEFAULT_FONT(12);
    
    UIView *NickCenterView = [[UIView alloc] init];
    [self addSubview:NickCenterView];
    [NickCenterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNickname);
        make.height.equalTo(@40);
        make.right.equalTo(self.level);
        make.centerX.equalTo(self);
        make.top.equalTo(self.headerImage.mas_bottom).offset(3);
    }];
    
    [self.userNickname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.level.mas_left).offset(-9);
        make.centerY.equalTo(NickCenterView);
        
    }];
    
    [self.level mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@10);
        make.width.equalTo(@22);
        make.centerY.equalTo(NickCenterView);
    }];
    
    [self.LBids mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(NickCenterView);
        make.top.equalTo(self.userNickname.mas_bottom).offset(5);
    }];
    
    self.level.titleLabel.font = DEFAULT_FONT(8);
    
}

- (IBAction)ClickAttr:(id)sender {
    
    if([self.delegae respondsToSelector: @selector(MineHeaderClickItemWithType:)])
    {
        [self.delegae MineHeaderClickItemWithType:CYMineClickTypeLeft];
    }
}

- (IBAction)ClickFans:(id)sender {
    
    if([self.delegae respondsToSelector: @selector(MineHeaderClickItemWithType:)])
    {
        [self.delegae MineHeaderClickItemWithType:CYMineClickTypeCenter];
    }
}

- (IBAction)clickRate:(id)sender {
    if([self.delegae respondsToSelector: @selector(MineHeaderClickItemWithType:)])
    {
        [self.delegae MineHeaderClickItemWithType:CYMineClickTypeRight];
    }
}

- (IBAction)headerClick:(id)sender {
    if([self.delegae respondsToSelector: @selector(MineHeaderClick)])
    {
        [self.delegae MineHeaderClick];
    }
}



-(void)setModel:(UserCenterModel *)model
{
    if(model == nil)
    {
        model = [UserCenterModel new];
    }
    _model = model;
    self.labAttrNum.text = model.attention_all;
    self.labFansNum.text = model.attention_fans;
    self.labRateNum.text = model.split;
}

-(void)updateData
{
    NSURL *imageurl = [[CYURLUtils sharedCYURLUtils] safeUrl:[UserManager sharedUserManager].curUserInfo.avatar];
    
    [self.headerImage sd_setBackgroundImageWithURL:imageurl forState:UIControlStateNormal];
    [self.level setFillColor:[UIColor qmui_colorWithHexString:@"54CEF5"]];
    [self.level setTitleColor:[UIColor qmui_colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    [self.level setTitle:[NSString stringWithFormat:@"LV.%@",curUser.level] forState:UIControlStateNormal];
    if(curUser.level == nil)
    {
        [self.level setTitle:[NSString stringWithFormat:@"LV.1"] forState:UIControlStateNormal];
    }
    //    [self.level getViewType:[NSString stringWithFormat:@"%d",curUser.sex] AndLevel:curUser.level];
    
    self.userNickname.text = curUser.user_nickname;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

